<?php
namespace App\WebSocket\Controller;


use App\Handler\WebSocket\ByAuthHandler;
use App\Handler\WebSocket\PingHandler;
use App\Handler\WebSocket\ProjectListHandler;
use App\Handler\WebSocket\ScreenAuthHandler;

class Index extends Base
{
    public $noCheckAction = ['ping', 'byAuth', 'screenAuth', 'projectList'];

    /**
     * 心跳
     * 推荐使用 easyswoole 自带的websocket客户端调试
     * http://www.easyswoole.com/wstool.html
     */
    public function ping()
    {
        $service = new PingHandler($this->fd, $this->content);
        $data = $service->handler();
//        var_dump(\EasySwoole\EasySwoole\ServerManager::getInstance()->getSwooleServer()->worker_id);
//        echo "心跳 heartbeat {$this->fd} \n";
        $this->response()->setMessage($data); // 推送消息
    }

    /**
     * 白友授权
     */
    public function byAuth()
    {
        $service = new ByAuthHandler($this->fd, $this->content);
        $data = $service->handler();

        $this->response()->setMessage($data); // 推送消息
    }

    /**
     * 大屏授权
     */
    public function screenAuth()
    {
        $service = new ScreenAuthHandler($this->fd, $this->content);
        $data = $service->handler();

        $this->response()->setMessage($data); // 推送消息
    }

    /**
     * 大屏授权
     */
    public function projectList()
    {
        $service = new ProjectListHandler($this->fd, $this->content);
        $data = $service->handler();

        $this->response()->setMessage($data); // 推送消息
    }
}
